'''
' Class to list tile state enums
'''
class TileState:
    ENEMY_LOCKED, ENEMY, NEUTRAL, FRIENDLY, FRIENDLY_LOCKED = range(5)

import pygame
from pygame.locals import *
import string

'''
' Class to manage a tile
'''
class Tile(pygame.Surface):    
    def __init__(self, letter='',x=0, y=0, size=0, above=None, left=None, below=None, right=None):
        pygame.Surface.__init__(self, (size, size))
        self.size = size
        self.letter = letter
        self.x = x
        self.y = y
        self.above = above
        self.left = left
        self.below = below
        self.right = right
        self.state = TileState.NEUTRAL
    def __str__(self):
        print "x:", self.x 
        print " y:", self.y
        print " letter:" + self.letter
    
    def __eq__(self, object):
        return self.size == object.size and self.letter == object.letter and self.x == object.x and self.y == object.y \
            and self.above == object.above and self.left == object.left and self.below == object.below and self.right == object.right and self.state == object.state
        
    def draw(self, pos):
        self.screen_pos = pos
        self.fill(self.get_state_color())
        pygame.draw.line(self, (0, 0, 0), (0,0), (0, self.size))
        pygame.draw.line(self, (0, 0, 0), (0,self.size-1), (self.size-1, self.size-1))
        pygame.draw.line(self, (0, 0, 0), (0,0), (self.size-1, 0))
        pygame.draw.line(self, (0, 0, 0), (self.size-1,0), (self.size-1, self.size-1))
        font = pygame.font.Font(None, 96)
        text = font.render(string.upper(self.letter), 1, (0, 0, 0))
        textPos = text.get_rect(centerx = self.size/2, centery = self.size/2)
        self.blit(text, textPos)
        return self
    
    def clicked(self):
        self.state = TileState.FRIENDLY
        self.fill(self.get_state_color())
        
    def get_state_color(self):
        return {
                TileState.NEUTRAL : pygame.Color(255, 255, 255),
                TileState.ENEMY : pygame.Color(255, 102, 102),
                TileState.ENEMY_LOCKED : pygame.Color(204, 0, 0),
                TileState.FRIENDLY : pygame.Color(102, 178, 255),
                TileState.FRIENDLY_LOCKED : pygame.Color(0, 102, 204)
                }.get(self.state, pygame.Color(255, 255, 255))